import {
  Entity,
  Column,
  PrimaryColumn,
  BeforeInsert,
  BeforeUpdate,
} from 'typeorm';
import { v4 as uuidv4 } from 'uuid';
import * as moment from 'moment';

@Entity({ name: 'code' })
export class CodeEntity {
  @PrimaryColumn()
  id: string = uuidv4();

  @Column({ type: 'varchar', nullable: true, length: 30, comment: '验证码' })
  code: string;

  @Column({ type: 'varchar', nullable: true })
  created_at: string;

  @Column({ type: 'varchar', nullable: true })
  updated_at: string;

  @BeforeInsert()
  createDates() {
    this.created_at = moment().format();
  }

  @BeforeUpdate()
  updateDates() {
    this.updated_at = moment().format();
  }
}
